package com.bcxj.serviceprice.controller;

import com.bcxj.internalcommon.dto.ResponseResult;
import com.bcxj.internalcommon.entity.PriceRule;
import com.bcxj.serviceprice.mapper.PriceRuleMapper;
import com.bcxj.serviceprice.service.PriceRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: PriceRuleController
 * Package: com.bcxj.serviceprice.controller
 * Description:
 *
 * @Author BCXJ
 * @Create 2024/11/9 23:32
 * @Version 1.0
 * @Since 1.0
 */
@RestController
@RequestMapping("/price-rule")
public class PriceRuleController {

    @Autowired
    private PriceRuleService priceRuleService;


    /**
     * 判断计价规则是否是最新的
     * @param fareType
     * @param fareVersion
     * @return
     */
    @GetMapping("is-new")
    public ResponseResult<Boolean> isNew(@RequestParam String fareType, @RequestParam Integer fareVersion) {
        return priceRuleService.isNew(fareType, fareVersion);
    }

    /**
     * 获取最新的计价规则
     * @param fareType
     * @return
     */
    @GetMapping("get-newest-version")
    public ResponseResult<PriceRule> getNewestVersion(@RequestParam String fareType){
        return priceRuleService.getNewestVersion(fareType);
    }


    /**
     * 添加计价规则
     * @param priceRule
     * @return
     */
    @PostMapping("/add")
    public ResponseResult add(@RequestBody PriceRule priceRule) {
        // 添加计价规则
        return priceRuleService.add(priceRule);
    }


    /**
     * 计价规则的修改
     * @param priceRule
     * @return
     */
    @PostMapping("edit")
    public ResponseResult edit(@RequestBody PriceRule priceRule) {
        return priceRuleService.edit(priceRule);
    }


    /**
     * 判断计价规则是否存在
     * @param address
     * @param vehicleType
     * @return
     */
    @GetMapping("/if-exists")
    public ResponseResult<Boolean> ifExists(@RequestParam String address, @RequestParam String vehicleType) {
        return priceRuleService.ifExists(address, vehicleType);
    }
}
